package com.prj.ufdm.cloud.ms.auth.api;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.prj.ufdm.cloud.base.dto.RetData;
import com.prj.ufdm.cloud.base.util.BaseUuidUtil;
import com.prj.ufdm.cloud.ms.core.bpo.SysAreaBPO;
import com.prj.ufdm.cloud.ms.core.model.PageBean;
import com.prj.ufdm.cloud.ms.core.model.SysArea;
import com.prj.ufdm.cloud.ms.core.model.SysAreaVO;

/**
 * DESC: 用户区域
 * @author zhengzixiang
 * @since 2019-09-27
 */
@RestController
@RequestMapping("/api/auth/sysArea")
public class SysAreaController {

 	@Autowired
    private SysAreaBPO sysAreaBPO;
    
    /**
   	 *查询列表
    */
    @RequestMapping("/doGetList")
	public RetData<PageInfo<SysArea>> doGetList(PageBean pageBean,SysArea t)  throws Exception {
		RetData<PageInfo<SysArea>> retData = new RetData<PageInfo<SysArea>>();
		PageHelper.startPage(pageBean.getPageNum(),pageBean.getPageSize());
		List<SysArea>  list=sysAreaBPO.doGetList(t);
		PageInfo<SysArea> page=new PageInfo<SysArea>(list);
		retData.setRetBody(page);
		return retData;
	}
    /**
   	 *查询列表
    */
    @RequestMapping("/doGetAll")
	public RetData<List<SysArea>> doGetAll()  throws Exception {
		RetData<List<SysArea>> retData = new RetData<List<SysArea>>();
		List<SysArea>  list=sysAreaBPO.getSysAreas(null);
		retData.setRetBody(list);
		return retData;
	}
	 /**
   	 *通过id查询
    */
	@RequestMapping("/doGetById")
	public RetData<SysArea> doGetById(String id)  throws Exception {
		RetData<SysArea> retData = new RetData<SysArea>();
		SysArea result=sysAreaBPO.doGetById(id);
		retData.setRetBody(result);
		return retData;
	}
	/**
   	 *保存/修改
    */
	@RequestMapping("/doSave")
	public RetData<String> doSave(SysArea t)throws Exception{
		RetData<String> ret=new RetData<String>();
		if(StringUtils.isBlank(t.getId())) {
			t.setId(BaseUuidUtil.getUUID());
			sysAreaBPO.doSave(t);
		}else {
			sysAreaBPO.doModById(t);
		}
		
		ret.setRetBody("");
		return ret;
	}
	
	/**
   	 *更新
    */
	@RequestMapping("/doModById")
	public RetData<String> doModById(SysArea t)throws Exception{
		RetData<String> ret=new RetData<String>();
		sysAreaBPO.doModById(t);
		ret.setRetBody("");
		return ret;
	}
	
	/**
   	 *删除
    */
	@RequestMapping("/doRmById")
	public RetData<String> doRmById(String id)throws Exception{
		RetData<String> ret=new RetData<String>();
		sysAreaBPO.doRmById(id);
		ret.setRetBody("");
		return ret;
	}
	
	/**
   	 *查询列表用于区域组件
    */
    @RequestMapping("/doGetSysAreaVOList")
	public RetData<List<SysAreaVO>> doGetSysAreaVOList()  throws Exception {
		RetData<List<SysAreaVO>> retData = new RetData<List<SysAreaVO>>();
		List<SysAreaVO>  list=sysAreaBPO.getSysAreaList("1");
		retData.setRetBody(list);
		return retData;
	}

}
